﻿@using Resources;
@using mojoPortal.Business.WebHelpers;
@model mojoPortal.Web.Models.FileManager

@{
	ViewBag.Title = Resource.FileManagerIndexHeaderTitle;
	ViewBag.AngularApp = "FileManagerApp";
	ViewBag.BodyClass = "ng-cloak" + ((Model.View == "fullpage" || (Model.Type == "file" || Model.Type == "folder")) ? " fullpage" : string.Empty);
	Layout = "~/Views/FileManager/_FileManagerLayout.cshtml";
	var siteSettings = CacheHelper.GetCurrentSiteSettings();
	var siteFolderName = String.IsNullOrWhiteSpace(siteSettings.SiteFolderName) ? "" : siteSettings.SiteFolderName + "/";
}

@if (Model.View == "fullpage")
{
	<div class="alert alert-info alert-control">
		<a class="alert-link" href="javascript:void(0)" onclick="history.back();"><i class="glyphicon glyphicon-menu-left" aria-hidden="true"></i> @Model.BackToWebsiteLinkText</a>
	</div>
}

@if (Model.Type == "file" || Model.Type == "folder")
{
	<div class="alert alert-info alert-control">
		<i class="glyphicon glyphicon-file"></i>
		@Html.ActionLink(Model.PagePickerLinkText, "Pages", Model.QueryString, new { @class = "alert-link" })
	</div>
}

<angular-filemanager></angular-filemanager>

@section Styles {
	<link rel="stylesheet" href="~/Content/FileManager/dist/angular-filemanager.min.css">
}

@section Scripts {
	<script src="~/Content/FileManager/bower_components/angular/angular.min.js"></script>
	<script src="~/Content/FileManager/bower_components/angular-translate/angular-translate.min.js"></script>
	<script src="~/Content/FileManager/bower_components/ng-file-upload/ng-file-upload.min.js"></script>
	<script src="~/Content/FileManager/dist/angular-filemanager.min.js"></script>
	<script>
		angular.module('FileManagerApp').config(['fileManagerConfigProvider', function(config) {
			var defaults = config.$get();

			config.set({
				appName: '@Model.RootName',
				pickCallback: function (item) {
					var url = '@Model.VirtualPath' + item.fullPath();

					@if (Model.Editor != null) {
						switch (Model.Editor) {
							case "ckeditor":
								<text>ckSubmit(url);</text>
								break;

							case "tinymce":
								<text>tmceSubmit(url);</text>
								break;

							case "filepicker":
							case "folderpicker":
								<text>fpSubmit(url);</text>
								break;
						}
					}
				},
				allowedActions: angular.extend(defaults.allowedActions, {
					pickFiles: @((Model.Editor != null && Model.Editor != "folderpicker") ? "true" : "false"),
					pickFolders: @((Model.Editor != null && Model.Editor == "folderpicker") ? "true" : "false"),
					changePermissions: false,
					upload: @Model.Upload,
					rename: @Model.Rename,
					move: @Model.Move,
					copy: @Model.Copy,
					edit: @Model.Edit,
					compress: @Model.Compress,
					compressChooseName: @Model.CompressChooseName,
					extract: @Model.Extract,
					download: @Model.Download,
					downloadMultiple: @Model.DownloadMultiple,
					preview: @Model.Preview,
					remove: @Model.Remove,
					createFolder: @Model.CreateFolder,
				}),
				listUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				uploadUrl: '@Url.Content("~")@(siteFolderName)fileservice/fileupload',
				renameUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				copyUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				moveUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				removeUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				editUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				getContentUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				createFolderUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				downloadFileUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				downloadMultipleUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				compressUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				extractUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				permissionsUrl: '@Url.Content("~")@(siteFolderName)fileservice',
				basePath: '/',
				fileSystemToken: '@Model.FileSystemToken',
				typeQueryString: '@Model.Type',
				hidePermissions: true,
				multipleDownloadFileName: 'angular-filemanager.zip'
			});
		}]);
	</script>
}